<?php
namespace app\web\plug;

use cubox\Cubox;
class Route{
    public function getData($param){
        $re = [];

        $app = Cubox::app('web');


        $part = $app->model('Part');
        $data = $part->where('route_type','in',['parent','root'])->where('route','not null')->getData();

        $re = [];

        foreach($data as $val){

            $route = $part->getRoute($val['part_id']);
            $re[$route] = [
                'app'=> 'web',
                'controller'=> 'index',
                'action'=> 'part',
                'gets'=> [
                    'id'=> $val['part_id']
                ]
            ];

            $readRoute = $route.'/:id';
            $re[$readRoute] = [
                'app'=> 'web',
                'controller'=> 'article',
                'action'=> 'read',
                'gets'=> [
                    'id'=> ':id'
                ]
            ];
        }


        //获取全部文章路由
        $article = $app->model('Article');
        $data = $article->where('route_type','in',['parent','root'])->where('route','not null')->getData();

        foreach($data as $val){

            $route = $article->getRoute($val,$part->frontData($val['part_id']));
            $re[$route] = [
                'app'=> 'web',
                'controller'=> 'article',
                'action'=> 'read',
                'gets'=> [
                    'id'=> $val['article_id']
                ]
            ];
        }


        //获取全部页面路由
        $page = $app->model('Page');
        $data = $page->where('route_type','in',['parent','root'])->where('route','not null')->getData();
        foreach($data as $val){

            $route = $page->getRoute($val);
            $re[$route] = [
                'app'=> 'web',
                'controller'=> 'index',
                'action'=> 'page',
                'gets'=> [
                    'id'=> $val['page_id']
                ]
            ];
        }
        return $re;
    }
}